#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main(int argv, char const** argc) {
    int n;
    cin >> n;
    string str = to_string(n);
    if (str.length() != 4) {
        cout << 0 << endl;
        return 0;
    }
    int max_prime = 0;
    for (int i = 0; i < str.length(); i++) {
        for (int j = i + 1; j <= str.length(); j++) {
            int num = stoi(str.substr(i, j - i));
            bool is_prime = true;
            if (num <= 1)
                is_prime = false;
            else {
                for (int k = 2; k <= sqrt(num); k++) {
                    if (num % k == 0) {
                        is_prime = false;
                        break;
                    }
                }
            }
            if (is_prime && num > max_prime)
                max_prime = num;
        }
    }
    cout << max_prime << endl;
    return 0;
}